<template>
  <div>
    <div class="maintable" style="width:1600px;padding-left:200px">
  <el-table
  :data="tableData"
  stripe
  style="width: 950; " :row-class-name="tableRowClassName">
  <el-table-column
  prop="courseId"
  label="课程编号"
  width="200">

    </el-table-column>
    <el-table-column
    prop="courseName"
    label="课程名称"
    width="200">
    </el-table-column>


    <el-table-column
    prop="teacherRealName"
    label="授课老师"
    width="200">
    <template slot-scope="scope">
      {{scope.row.teacher.teacherRealname}}
    </template>
    </el-table-column>

    <el-table-column
    prop="courseScore"
    label="学分"
    width="150">
    </el-table-column>
    <el-table-column
    label="课程评价"
    width="150"
    >
    <template slot-scope="scope">
          <el-button type="primary" @click="courseEvaluate(scope.row)" >课程评价</el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
<el-dialog title="评价" :visible.sync="dialogFormVisible">
  <el-form :model="form">
    <el-form-item label="个人评价"
      prop="classEvaluateContent"
    :label-width="formLabelWidth">
      <el-input type="textarea" v-model="form.classEvaluateContent" auto-complete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="submitForm">确 定</el-button>
  </div>
</el-dialog>
  <div class="block">
  <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="pageIndex"
    :page-size="pageSize"
    layout="total, sizes, prev, pager, next, jumper"
    :total="400">
  </el-pagination>
  </div>
</div>
</template>
<style>


  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>

<script>
import {listCourse,saveCourseEvaluate}  from '@/axios/api'
export default {
  data() {

    return {
      pageIndex:1,
      pageSize:10,
      total:0,
      courseId:1,
      tableData: [
    ],
    dialogFormVisible: false,
       form: {
        classEvaluateContent: ''
       },
       formLabelWidth: '120px'
  }
},
  methods : {
    courseEvaluate:function(row){
      this.dialogFormVisible = true;
      this.courseId = row.courseId;
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageIndex = parseInt('${val}');
      this.listCourse()
    },
    submitForm(){
      this.dialogFormVisible = false;
      let para = {
        courseId: this.courseId,
        classEvaluateContent : this.form.classEvaluateContent
      }
      saveCourseEvaluate(para).then(res => {
        if(res.status == 200){
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success'
          })
        }else{
          this.$message({
            showClose: true,
            message: res.message,
            type: 'error'
          });
        }
      })
    },
      getListCourse(){
       let param  = {pageIndex:this.pageIndex}
       listCourse(param).then(res=> {
         this.tableData = res.resData.list;
         this.pageSize = res.resData.pageSize;
         this.total = res.resData.total;
       })
      }

  },
  mounted(){
    this.getListCourse();
  }
}
</script>
